package djrain.lilochat.client;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import djrain.lib.ToastEx;

public class UnitItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	public UnitItemizedOverlay(Context context, Drawable defaultMarker)
	{
		super(boundCenterBottom(defaultMarker));
		mContext = context;
		((AnimationDrawable) defaultMarker).start();
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow)
	{
		// TODO Auto-generated method stub
		Log.i("djrain", "UnitItemizedOverlay draw(Canvas canvas, MapView mapView, boolean shadow)");
		// canvas.drawRect(0,0,100,100,new Paint());
		super.draw(canvas, mapView, shadow);
	}

	// @Override
	// public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long
	// when) {
	// // TODO Auto-generated method stub
	// //
	// Log.i("djrain","UnitItemizedOverlay public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)");
	// canvas.drawRect(0,0,100,100,new Paint());
	// return super.draw(canvas, mapView, false, 1000);
	// }

	@Override
	protected OverlayItem createItem(int i)
	{
		return mOverlays.get(i);
	}

	@Override
	public int size()
	{
		return mOverlays.size();
	}

	public void addOverlay(OverlayItem overlay)
	{
		mOverlays.add(overlay);
		populate();
	}

	// @Override
	// public boolean onSnapToItem(int x, int y, Point snapPoint, MapView
	// mapView) {
	// Log.i("djrain","UnitItemizedOverlay onSnapToItem:");
	// return super.onSnapToItem(x, y, snapPoint, mapView);
	// }

	@Override
	protected boolean onTap(int index)
	{
		OverlayItem item = mOverlays.get(index);
		ToastEx.makeText(mContext, item.getTitle());
		// new AlertDialog.Builder(mContext)
		// .setIcon(R.drawable.icon)
		// .setTitle( item.getTitle() )
		// .show();
		return true;
	}
}
